  <template>
  <div class="bill-materials" align="center">
	  <div class="title">材料{{orderReport}}单</div>
	  <div class="tip">
	  	<span class="tip-a">单据号:{{dataOrDet.id}}</span>
      <span class="tip-b">自编号:{{dataOrDet.orderNum}}</span>
      <span class="tip-a">制单人:{{dataOrDet.createUserName}}</span>
      <span class="tip-a">审核人:{{dataOrDet.auditUserName}}</span>
      <span class="tip-a" style="width: 200px">审核日期:{{dataOrDet.auditTime}}</span>
	  </div>
	  <div class="info">
  	  <table class="info-table" cellspacing="0" width="100%">
        <tbody>          
          <!--<tr>
            <td colspan="2">{{type? outTypeText[0] : inTypeText[0]}}</td>
            <td colspan="3">{{type? dataOrDet.storageName : dataOrDet.supName}}</td>
            <td colspan="2">{{type? outTypeText[1] : inTypeText[1]}}</td>
            <td colspan="4">{{type? dataOrDet.localName : dataOrDet.contactName}}</td>
          </tr>
          <tr>
            <td colspan="4">{{type? outTypeText[2]:inTypeText[2]}}</td>
            <td colspan="7">{{type? dataOrDet.shippingUnit : ""}}</td>
          </tr>-->
          <tr v-if="type == '0'">
            <td colspan="2">{{inTypeText[0]}}</td>
            <td colspan="3">{{dataOrDet.supName}}</td>
            <td colspan="2">{{inTypeText[1]}}</td>
            <td colspan="4">{{dataOrDet.contactName}}</td>
          </tr>
          <tr v-if="type == '1'">
            <td colspan="3">仓库</td>
            <td colspan="3">{{dataOrDet.storageName}}</td>
            <td colspan="3">库区</td>
            <td colspan="4">{{dataOrDet.localName}}</td>           
          </tr>
          <tr class="goods-message">
              <td>物品编号</td>
              <td>物品名称</td>
              <td>品牌</td>
              <td>规格型号</td>
              <td>单位</td>
              <td>数量</td>
              <td>成本单价（元）</td>
              <td>成本金额（元）</td>
              <td v-if="type == '1'">源仓库</td>
              <td v-if="type == '1'">源库区</td>              
              <td>{{type == "0" ? "仓库" : "部门"}}</td>
              <td>{{type == "0" ? "库区" : "工单" }}</td>
              <td>备注</td>
          </tr> 
          <tr v-for="(item,index) in orderDetailsList" :key="index">     
          	<td>{{item.itemNum}}</td>     
          	<td>{{item.itemName}}</td>     
          	<td>{{item.brand}}</td>     
          	<td>{{item.size}}</td>    
          	<td>{{item.unitName}}</td>     
          	<td>{{item.num}}</td>
            <td>{{type == "0" ? item.inPrice : item.outPrice}}</td>        
          	<td>{{item.amount}}</td>
            <td v-if="type == '1'">{{item.storageName}}</td>
            <td v-if="type == '1'">{{item.localName}}</td>
            <td>{{type == "0" ? item.storageName : item.departmentName}}</td>
            <td>{{type == "0" ? item.localName : item.workOrderName}}</td>   
          	<td class="small-size" >{{item.outMemo? item.outMemo : item.inMemo}}</td> 
          </tr>
          <tr>
              <td colspan="6">合计</td>
              <td class="small-count" colspan="2">{{totalPriceAll}}</td>
              <td colspan="5"></td>
          </tr>
        </tbody>
      </table>
	  </div>
	  <div class="sign">
	  	<span class="tip-b">维保部负责人签字:</span>
      <span class="tip-b">综合维修中心签字:</span>
      <span class="tip-c">后勤部门负责人签字:</span>
      <span class="tip-a">主管签字:</span>
      <span class="tip-a">仓管员签字:</span>
	  </div>
	</div>
</template>
<script>
import API from "../api";
//type? dataType[dataOrDet.outType-1].name : dataType[dataOrDet.inType-1].name
export default {
  name: "bill-materials",
  props: ["dataOrDet"],
  data() {
    return {
      inTypeText: ["供货单位：", "联系人：", "项目名称："],
      outTypeText: ["仓库：", "库区：", "出货单位："],
      totalPriceAll: "",
      orderReport: "",
      //dataOrDet: [],
      type: "",
      orderDetailsList: []
    };
  },
  mounted() {},

  updated() {},

  methods: {
    totalPrice() {
      let totalPrice = 0;
      for (let i = 0; i < this.orderDetailsList.length; i++) {
        totalPrice = totalPrice + this.orderDetailsList[i].amount;
      }
      this.totalPriceAll = totalPrice;
    },

    getInDetailsList(obj) {
      API.getInDetailsList(obj)
        .then(res => {
          if (res.code == 200) {
            let dataDet = res.data;
            if (dataDet != null) {
              this.orderDetailsList = dataDet.list; //请求赋值物品列表
              this.totalPrice();
            } else {
              this.orderDetailsList = [];
              this.totalPriceAll = "";
              this.$Message.success({ content: "暂无数据！" });
            }
          }
        })
        .catch(err => {
          this.$Message.error("请求异常！");
          console.log("getInDetailsList", err);
        });
    },

    getOutDetailsList(obj) {
      API.getOutDetailsList(obj)
        .then(res => {
          if (res.code == 200) {
            let dataDet = res.data;
            if (dataDet != null) {
              this.orderDetailsList = dataDet.list; //请求赋值物品列表
              this.totalPrice();
            } else {
              this.orderDetailsList = [];
              this.totalPriceAll = "";
              this.$Message.success({ content: "暂无数据！" });
            }
          }
        })
        .catch(err => {
          this.$Message.error("请求异常！");
          console.log("getOutDetailsList", err);
        });
    },

    getInList(obj) {
      API.getInList(obj)
        .then(res => {
          if (res.code == 200) {
            let dataDet = res.data;
            if (dataDet != null) {
              this.dataOrDet = dataDet.list[0]; //请求赋值物品列表
              this.totalPrice();
            } else {
              this.orderDetailsList = [];
              this.totalPriceAll = "";
              this.$Message.success({ content: "暂无数据！" });
            }
          }
        })
        .catch(err => {
          this.$Message.error("请求异常！");
          console.log("getInList", err);
        });
    },

    getOutList(obj) {
      API.getOutList(obj)
        .then(res => {
          if (res.code == 200) {
            let dataDet = res.data;
            if (dataDet != null) {
              this.dataOrDet = dataDet.list[0]; //请求赋值物品列表
              this.totalPrice();
            } else {
              this.orderDetailsList = [];
              this.totalPriceAll = "";
              this.$Message.success({ content: "暂无数据！" });
            }
          }
        })
        .catch(err => {
          this.$Message.error("请求异常！");
          console.log("getOutList", err);
        });
    },

    orderDetails(orderReport, orderNum, inOutType, parameter) {
      //console.log(this.dataOrDet);
      this.orderReport = orderReport;
      this.type = inOutType;
      let obj = {
        orderNum: orderNum,
        userID: "",
        userName: "",
        b_UserRole: ""
      };

      let objA = {
        orderNum: orderNum,
        storageNums: ["1", "2", "3"],
        userID: "",
        userName: "",
        b_UserRole: ""
      };

      if (inOutType == "0") {
        this.getInDetailsList(obj);
        if (parameter == "1") {
          this.getInList(objA);
        }
      } else {
        this.getOutDetailsList(obj);
        if (parameter == "1") {
          this.getOutList(objA);
        }
      }
    }
  },

  created() {
    //this.data
  }
};
</script>
<style lang="less" >
.bill-materials {
  width: 1000px;
  border: 1px solid #ccc;
  margin: 0 auto;
  border-radius: 3px;
  padding: 10px;

  .title {
    text-align: center;
    height: 80px;
    line-height: 80px;
    font-size: 30px;
    font-weight: 600;
  }

  .tip-a {
    display: inline-block;
    height: 30px;
    width: 150px;
  }
  .tip-b {
    display: inline-block;
    height: 30px;
    width: 200px;
  }
  .tip-c {
    display: inline-block;
    height: 30px;
    width: 250px;
  }

  .info-table {
    table,
    tr,
    td {
      border: 1px solid #ccc;
    }
    td {
      height: 40px;
      min-width: 70px;
      text-align: center;
    }
  }

  .sign {
    height: 80px;
    padding-top: 10px;
  }
}
</style>
